<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
        let p1 = new Promise((resolve,reject) => {
            setTimeout(() => {
                resolve(111)
                // reject('err')
            },1000)
        })
        let p2 = new Promise((resolve,reject) =>{
            setTimeout(() => resolve(222),2000)
        })
        // Promise.all([p1,p2]).then(res=>{
        //     console.log(res)
        // })
        function myPromiseAll(lists){
            return new Promise((resolve,reject) =>{
                let resArr = []
                let num = 0
                lists.forEach(item => {
                    item.then(res=>{
                        resArr = [...resArr,res]
                        num++
                        if(num === lists.length){
                            resolve(resArr)
                        }
                    })
                });
            })
        }
        myPromiseAll([p1,p2]).then(res => {
            console.log(res)
        })
    </script>
</body>
</html>